package com.aistar.controller;

import com.aistar.mapper.EmployeeBlacklistMapper;
import com.aistar.model.bo.Result;
import com.aistar.model.entity.Employee;
import com.aistar.model.entity.User;
import com.aistar.service.resume.IResumeService;
import com.aistar.service.user.IEmployeeInfoService;
import com.aistar.service.user.IMyblacklistService;
import com.aistar.service.user.IMycollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * @ClassName: UserRestController
 * @author: LiuWenXiu
 * @date: 2021/9/26 15:48
 * @Description: TODO...本类用来演示:
 */
@RestController
@RequestMapping("/user")
public class UserRestController {
    @Autowired
    private IMyblacklistService myblacklistService;

    @Autowired
    private IMycollectionService mycollectionService;

    @Autowired
    private IEmployeeInfoService employeeInfoService;

    @Autowired
    private IResumeService resumeService;


    @PostMapping("/delete/blacklist")
//    @ResponseBody
    public Result delBlacklist(HttpServletRequest request,Integer cid) {

        HttpSession session=request.getSession();
        Integer eid= ((Employee) session.getAttribute("employee")).getId();
        int count = myblacklistService.DeleteBlack(eid, cid);
        if (count != 0) {
            return new Result("200", "删除成功");
        }
        return new Result("500", "删除失败");
    }
    @PostMapping("/delete/collection")
    public Result delCollection(HttpServletRequest request,Integer rid){
        HttpSession session =request.getSession();
        Integer eid = ((Employee) session.getAttribute("employee")).getId();
        int count = mycollectionService.deleteCollection(eid,rid);
        if (count !=0)
            return new Result("200","删除成功");
        return new Result("500","删除失败");
    }

    @PostMapping("/update/userInfo")
    public Result updateResume(HttpServletRequest request){
        HttpSession session = request.getSession();
        Integer eid = ((Employee) session.getAttribute("employee")).getId();
        System.out.println(eid);
        int count = employeeInfoService.updateTime(eid);
        if (count !=0)
            return new Result("200","删除成功");
        return new Result("500","删除失败");
    }

    @PostMapping("/delete/resume")
    public Result deleteResume(Integer resumeId){
        int count = resumeService.updateStatusById(resumeId);
        if (count !=0)
            return new Result("200","删除成功");
        return new Result("500","删除失败");
    }

    @PostMapping("/update/privacy")
    public Result updatePrivacy(Integer resumeId){
        int count = employeeInfoService.privacyChange(resumeId);
        if (count !=0)
            return new Result("200","删除成功");
        return new Result("500","删除失败");
    }
    @PostMapping("/update/possword")
    public Result changePassword(String oldPassword,String newPassword,String newPasswordAgain){
        System.out.println(oldPassword);
        System.out.println(newPassword);
        System.out.println(newPasswordAgain);
        int count = 0;
        if (count !=0)
            return new Result("200","修改成功");
        return new Result("500","修改失败");
    }
}
